package controllers;

import java.util.List;

import models.Department;
import models.Employee;
import play.mvc.Controller;
import dao.DepartmentDao;
import dao.EmployeeDao;

public class Departments extends Controller {

	public static void index() {
		DepartmentDao departmentDao = new DepartmentDao();
		List<Department> entities = departmentDao.findAll();
		render(entities);
	}

	public static void create(Department department) {
		render(department);
	}

	public static void save(Department department) {
		DepartmentDao DepartmentDao = new DepartmentDao();
		DepartmentDao.save(department);
		index();
	}

	public static void edit(Long id) {
		DepartmentDao departmentDao = new DepartmentDao();
		Department  department = departmentDao.findById(id);
		render("departments/create.html", department);
	}

	public static void delete(Long id) {
		DepartmentDao departmentDao = new DepartmentDao();
		departmentDao.delete(id);
		index();
	}
	
	public static void allDepartmentEmployees(Long id) {
		EmployeeDao employeeDao = new EmployeeDao();
		List<Employee> entities = employeeDao.findAllDepartmentEmployees(id);
		render("Employees/index.html", entities);
	}

}
